#
# COPYRIGHT (C) 2017-2021, zhllxt
# 
# author   : zhllxt
# email    : 37792738@qq.com
# 
# Distributed under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
# (See accompanying file LICENSE or see <http://www.gnu.org/licenses/>)
#

#GroupSources (include/asio2 "/")
#GroupSources (3rd/asio "/")

aux_source_directory(. SRC_FILES)

source_group("" FILES ${SRC_FILES})

function (AddExecutableTarget PROJECT_NAME)
    set(TARGET_NAME test_${PROJECT_NAME})
	link_directories(${ASIO2_LIBS_DIR})
    add_executable (${TARGET_NAME} ${PROJECT_NAME}.cpp)
    add_test(NAME test_${TARGET_NAME} COMMAND ${TARGET_NAME} WORKING_DIRECTORY ${ASIO2_EXES_DIR})
    set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER "test/unit")
    set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ASIO2_EXES_DIR})
    target_link_libraries(${TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
    target_link_libraries(${TARGET_NAME} ${GENERAL_LIBS})
	if (MSVC)
      set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "/ignore:4099")
    endif()
endfunction()

function (AddUtilExecutableTarget PROJECT_NAME)
    set(TARGET_NAME test_${PROJECT_NAME})
	link_directories(${ASIO2_LIBS_DIR})
    add_executable (${TARGET_NAME} ${PROJECT_NAME}.cpp)
    add_test(NAME test_${TARGET_NAME} COMMAND ${TARGET_NAME} WORKING_DIRECTORY ${ASIO2_EXES_DIR})
    set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER "test/unit/utils")
    set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ASIO2_EXES_DIR})
    target_link_libraries(${TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
    target_link_libraries(${TARGET_NAME} ${GENERAL_LIBS})
	if (MSVC)
      set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "/ignore:4099")
    endif()
endfunction()

function (AddSslExecutableTarget PROJECT_NAME)
    set(TARGET_NAME test_${PROJECT_NAME})
	link_directories(${ASIO2_LIBS_DIR})
    add_executable (${TARGET_NAME} ${PROJECT_NAME}.cpp)
    add_test(NAME test_${TARGET_NAME} COMMAND ${TARGET_NAME} WORKING_DIRECTORY ${ASIO2_EXES_DIR})
    set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER "test/unit/ssl")
    set_target_properties(${TARGET_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${ASIO2_EXES_DIR})
	target_link_libraries(${TARGET_NAME} ${OPENSSL_LIBS})
    target_link_libraries(${TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
    target_link_libraries(${TARGET_NAME} ${GENERAL_LIBS})
	if (MSVC)
      set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "/ignore:4099")
    endif()
endfunction()

AddExecutableTarget(mqtt)
AddExecutableTarget(rpc1)
AddExecutableTarget(rpc2)
AddExecutableTarget(rpc3)
AddExecutableTarget(rpc4)
AddExecutableTarget(rpc5)
AddExecutableTarget(rpc_kcp1)
AddExecutableTarget(rpc_kcp2)
AddExecutableTarget(rpc_kcp3)
AddExecutableTarget(rpc_kcp4)
AddExecutableTarget(timer)
AddExecutableTarget(timer_enable_error)
AddExecutableTarget(http1)
AddExecutableTarget(http2)
AddExecutableTarget(http3)
AddExecutableTarget(http4)
AddExecutableTarget(shared_iopool)
AddExecutableTarget(tcp_general)
AddExecutableTarget(tcp_dgram)
AddExecutableTarget(tcp_custom)
AddExecutableTarget(websocket)
AddExecutableTarget(udp)
AddExecutableTarget(rate_limit_http)
AddExecutableTarget(rate_limit_rpc)
AddExecutableTarget(rate_limit_tcp)
AddExecutableTarget(rate_limit_ws)
AddExecutableTarget(socks5_rpc)
AddExecutableTarget(socks5_tcp)
AddExecutableTarget(socks5_udp)

AddUtilExecutableTarget(aes)
AddUtilExecutableTarget(base64)
AddUtilExecutableTarget(codecvt)
AddUtilExecutableTarget(des)
AddUtilExecutableTarget(ini)
AddUtilExecutableTarget(md5)
AddUtilExecutableTarget(sha1)
AddUtilExecutableTarget(uuid)
AddUtilExecutableTarget(thread_pool)
AddUtilExecutableTarget(zlib)
AddUtilExecutableTarget(event_dispatcher)
AddUtilExecutableTarget(reflection)
AddUtilExecutableTarget(strutil)

AddSslExecutableTarget(https1)
AddSslExecutableTarget(https2)
AddSslExecutableTarget(https3)
AddSslExecutableTarget(mqtts)
AddSslExecutableTarget(mqtts_server)
AddSslExecutableTarget(mysql)
AddSslExecutableTarget(rdc1)
AddSslExecutableTarget(rdc2)
AddSslExecutableTarget(rdc3)
AddSslExecutableTarget(rdc4)
AddSslExecutableTarget(rdc5)
AddSslExecutableTarget(rdc6)
AddSslExecutableTarget(rdc7)
AddSslExecutableTarget(rate_limit_tcps)
AddSslExecutableTarget(rate_limit_https)
AddSslExecutableTarget(rate_limit_rpcs)
AddSslExecutableTarget(rate_limit_wss)
AddSslExecutableTarget(start_stop)
